<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .tishifu{
            margin-left: 10px;
            font-size: 16px;
        }
        .tishifu.right::after{
            content: "恭喜您，用户名输入成功！";
            color: green;
        }
        .tishifu.wrong::after{
            content: "用户名错误，请重新输入！";
            color: red;
        }
    </style>
</head>
<body>
    <div class="name">
        <label for="username">用户名：</label>
        <input type="text" id="username" class="username" >
        <span class="tishifu"></span>
    </div>
    <script>
        const usernamePattern = /^[a-zA-Z0-9_-]{6,16}$/;
        const usernameInput = document.getElementById('username');
        const tishifu = document.querySelector('.tishifu')
        usernameInput.addEventListener('blur', function() {
            const username = this.value;
            tishifu.classList.remove('right','wrong')
        if (usernamePattern.test(username)) {
            // 符合规范：添加right类
            tishifu.classList.add('right');
        } else {
            // 不符合规范：添加wrong类
            tishifu.classList.add('wrong');
        }
        })
    </script>
</body>
</html>